﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectNocturnalFool
{
    class PartySelectPanel : PanelControl
    {
        ButtonControl cancelBtn, loadBtn, randomBtn, continueBtn;
        PartyMemberPanel portrait1, portrait2, portrait3, portrait4;

        public override int width
        {
            get
            {
                return base.width;
            }
            set
            {
                base.width = value;

                if (cancelBtn != null)
                {
                    int[] space = Util.spaceEvenX(2, cancelBtn.width, width);
                    cancelBtn.x = x + space[0];
                    continueBtn.x = x + space[1];

                    int[] portraitSpace = Util.spaceEvenX(4, portrait1.width, width);
                    portrait1.x = x + portraitSpace[0];
                    portrait2.x = x + portraitSpace[1];
                    portrait3.x = x + portraitSpace[2];
                    portrait4.x = x + portraitSpace[3];
                }
            }
        }

        public override void LoadContent()
        {
            base.LoadContent();
            width = 100;
            height = 100;

            int prevCtrl = y + Constants.ControlOffsets;
            int alignMiddle = Util.getCentreDrawPointX(x, Constants.ButtonWidthWide, 1);

            cancelBtn = new ButtonControl();
            cancelBtn.LoadContent();
            cancelBtn.yAnchor = VerticleAnchor.Bottom;
            cancelBtn.type = Button_Type.PartySelectCancel;
            cancelBtn.style = Button_Style.Short;
            cancelBtn.y = (y + height) - (cancelBtn.height + Constants.ControlSmallOffsets);

            continueBtn = new ButtonControl();
            continueBtn.LoadContent();
            continueBtn.yAnchor = VerticleAnchor.Bottom;
            continueBtn.type = Button_Type.PartySelectBegin;
            continueBtn.style = Button_Style.Short;
            continueBtn.y = (y + height) - (cancelBtn.height + Constants.ControlSmallOffsets);
            prevCtrl = (y + height) - (cancelBtn.height + Constants.ControlSmallOffsets) - (cancelBtn.height + Constants.ControlOffsets);
            

            loadBtn = new ButtonControl();
            loadBtn.LoadContent();
            loadBtn.yAnchor = VerticleAnchor.Bottom;
            loadBtn.xAnchor = HorizontalAnchor.Middle;
            loadBtn.type = Button_Type.PartySelectLoad;
            loadBtn.style = Button_Style.Long;
            loadBtn.y = prevCtrl;
            loadBtn.x = alignMiddle;
            prevCtrl += -(cancelBtn.height + Constants.ControlSmallOffsets);

            randomBtn = new ButtonControl();
            randomBtn.LoadContent();
            randomBtn.yAnchor = VerticleAnchor.Bottom;
            randomBtn.xAnchor = HorizontalAnchor.Middle;
            randomBtn.type = Button_Type.PartySelectRandom;
            randomBtn.style = Button_Style.Long;
            randomBtn.y = prevCtrl;
            randomBtn.x = alignMiddle;

            portrait1 = new PartyMemberPanel();
            portrait1.LoadContent();
            portrait1.yAnchor = VerticleAnchor.Top;
            portrait1.xAnchor = HorizontalAnchor.Left;
            portrait1.y = y + Constants.ControlSmallOffsets;
            portrait1.characterIndex = 0;

            portrait2 = new PartyMemberPanel();
            portrait2.LoadContent();
            portrait2.yAnchor = VerticleAnchor.Top;
            portrait2.xAnchor = HorizontalAnchor.Left;
            portrait2.y = y + Constants.ControlSmallOffsets;
            portrait2.characterIndex = 1;

            portrait3 = new PartyMemberPanel();
            portrait3.LoadContent();
            portrait3.yAnchor = VerticleAnchor.Top;
            portrait3.xAnchor = HorizontalAnchor.Left;
            portrait3.y = y + Constants.ControlSmallOffsets;
            portrait3.characterIndex = 2;

            portrait4 = new PartyMemberPanel();
            portrait4.LoadContent();
            portrait4.yAnchor = VerticleAnchor.Top;
            portrait4.xAnchor = HorizontalAnchor.Left;
            portrait4.y = y + Constants.ControlSmallOffsets;
            portrait4.characterIndex = 3;

            controls.Add(cancelBtn);
            controls.Add(loadBtn);
            controls.Add(randomBtn);
            controls.Add(continueBtn);
            controls.Add(portrait1);
            controls.Add(portrait2);
            controls.Add(portrait3);
            controls.Add(portrait4);
        }

    }
}
